package com.qingke.besuper.command.impl;

import com.qingke.besuper.app.BeSuperDAO;
import com.qingke.besuper.pojo.Question;
import com.qingke.besuper.pojo.User;
import com.qingke.besuper.util.BeSuperConsole;

public interface UpdateQuestionIsOpen {
	public default void UpdateQuestionIsOpenCommand(boolean isOpen,User user){
		BeSuperDAO dao=new BeSuperDAO();
		String isOpenStr;
		if(isOpen)
			isOpenStr="open";
		else
			isOpenStr="close";
		String num=BeSuperConsole.promptNotEmpty("Please input question id:").trim();
		if(!num.replaceAll("[0-9]","").equals("")){
			BeSuperConsole.println("err input");
			return ;
		}
		int questionId=Integer.parseInt(num);
		Question q=dao.getQuestionByQuestionId(questionId);
		if(q.getPlayerId()!=user.getId()){
			BeSuperConsole.println("It's not your question.");
			return ;
		}
		if(q.isOpen()){
			BeSuperConsole.println("The question have been "+isOpenStr+"ed.");
			return ;
		}
		int isSuccess=dao.updateIsOpen(q.getId(),isOpen);
		if(isSuccess>0)
			BeSuperConsole.println(isOpenStr+" success");
		else
			BeSuperConsole.println(isOpenStr+" failed");
	}
}
